home *** CD-ROM | disk | FTP | other *** search
- Path: crl.crl.com!not-for-mail
- From: bobfry@crl.com (Robert Fry)
- Newsgroups: comp.lang.c
- Subject: Re: Memory leakage
- Date: 19 Apr 1996 08:30:00 -0700
- Organization: CRL Dialup Internet Access
- Message-ID: <4l8bho$6m8@crl.crl.com>
- References: <4l3582$1v@alice.walrus.com>
- NNTP-Posting-Host: crl.com
-
- warrenj@walrus.com (Warren Johnson) writes:
-
- >Suppose I have a function:
-
- >int give_number() {
- > ...
- > ...
- > ...
- >}
-
- >and in main I have a line :
-
- >if(x>give_number()) {
- > ...
- > ... }
-
- >Now my question is this: give_number() returns an integer. Obviously
- >the compiler must allocate memory for this integer. However, we are not
- >returning this integer to an integer pointer, therefore this allocated
- >memory is floating about in the void somewhere without something pointing
- >to it. Is this memory deallocated when the function is finished running
- >it's course or do i have to do this:
-
- Actually, most compilers don't need to allocate memory for this integer.
- They do need to keep track of where it's stored (in most computers I've
- used, it's either in a register on the CPU or on the top of the stack).
- However, both of these locations are quite volatile; most compilers have
- no trouble reusing those spaces when you get to the next statement --
- there is no need to worry about allocation and freeing of space /in this
- circumstance/.
-
- Now, should you want to use the value returned by give_number()
- elsewhere, you will need to store it someplace you can get back to --
- such as a variable or a dynamically allocated space.
-
- Hope that helps!
- Bob
-